package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.injector.methods.UpdateById;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class NursingLevelServiceImpl extends ServiceImpl<NursingLevelMapper,NursingLevel> implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    // 获取所有护理等级数据
//    @Override
//    public List<NursingLevelVo> listAll() {
//        List<NursingLevelVo> nursingLevels = nursingLevelMapper.listAll();
//        return nursingLevels;
//    }
//    @Override
//    public List<NursingLevelVo> listAll() {
//        return BeanUtil.copyToList(list(),NursingLevelVo.class);
//    }

    // 批量插入护理等级数据
//    @Override
//    public void insertBatch(List<NursingLevelDto> nursingLevels) {
//        List<NursingLevel> levels = BeanUtil.copyToList(nursingLevels, NursingLevel.class);
//        nursingLevelMapper.insertBatch(levels);
//    }
//    @Override
//    public void insertBatch(List<NursingLevelDto> nursingLevels) {
//        saveBatch(BeanUtil.copyToList(nursingLevels, NursingLevel.class));
//    }

    // 根据id获取护理等级数据
//    @Override
//    public NursingLevelVo getById(Long id) {
//        return BeanUtil.toBean(nursingLevelMapper.getById(id), NursingLevelVo.class);
//    }

    // 更新护理等级数据
//    @Override
//    public void update(NursingLevelDto nursingLevel) {
//        NursingLevel level = BeanUtil.toBean(nursingLevel, NursingLevel.class);
//        nursingLevelMapper.update(level);
//    }

    // 删除护理等级数据
//    @Override
//    public void delete(Long id) {
//        nursingLevelMapper.delete(id);
//    }


    // 分页查询护理等级数据
    @Override
    public PageResponse<NursingLevelVo> listByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        // 使用pagehelper进行分页查询护理等级数据
        PageHelper.startPage(pageNum, pageSize);
        Page<List<NursingLevel>> page = nursingLevelMapper.listByPage(pageNum, pageSize, name, status);
        // 封装分页信息
        return  PageResponse.of(page, NursingLevelVo.class);
    }

    //启用/禁用护理等级
//    @Override
//    public void enableOrDisable(Long id, Integer status) {
//        nursingLevelMapper.updateStatus(id, status);
//    }

    //根据护理计划id集合查询护理等级列表
//    @Override
//    public List<NursingLevel> listAllByPlanIds(List<Long> ids) {
//        return nursingLevelMapper.listAllByPlanIds(ids);
//    }
    @Override
    public List<NursingLevel> listAllByPlanIds(List<Long> ids) {
        //sql  SELECT * FROM nursing_level  WHERE lplan_id in () ORDER BY create_by desc
        LambdaQueryWrapper<NursingLevel> lqw = new LambdaQueryWrapper<>();
        lqw.in(NursingLevel::getPlanId,ids);
        lqw.orderBy(true,false,NursingLevel::getCreateBy);
        return list(lqw);
    }

    // 插入护理等级数据
//    @Override
//    public void insert(NursingLevelDto nursingLevel) {
//        NursingLevel level = BeanUtil.toBean(nursingLevel, NursingLevel.class);
//        nursingLevelMapper.insert(level);
//    }
//    @Override
//    public void insert(NursingLevelDto nursingLevel) {
//        save(BeanUtil.toBean(nursingLevel, NursingLevel.class));
//    }
}

